﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Text;
using System.IO;


namespace Zen4SyncTestServerHost
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Opens both Test Server and Zen4SyncClient configuration files after the installation
        /// is completed.
        /// The files are open using the default application for .config file on the target machine.
        /// </summary>
        /// <param name="savedState"></param>
        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);

            // The installation directory is added in the Context via CustomActionData.
            // See the "Custom Actions Editor" of the Zen4SyncTestServerSetup project.
            string testServerInstallDir = Context.Parameters["targetdir"];
            
            string testServerConfigFile = Path.Combine(testServerInstallDir, "Zen4SyncTestServerHost.exe.config");
            string clientConfigFile = Path.Combine(testServerInstallDir, @"Zen4SyncClient\Zen4SyncClient.exe.config");

            System.Diagnostics.Process.Start(testServerConfigFile);
            System.Diagnostics.Process.Start(clientConfigFile);
        }
    }
}
